import { _decorator, Animation, Component, EditBox, Node, Vec3 } from 'cc';
import { GLOBALUtil } from './GlobalUtil';
const { ccclass, property } = _decorator;

@ccclass('FeedbackManager')
export class FeedbackManager extends Component {
    @property({type: Node, tooltip: "feedbackPanel"})
    private feedbackPanel: Node = null;
    @property({type: Node, tooltip: "FeedbackBox"})
    private FeedbackBox: Node = null;
    protected onEnable(): void {
        //播放动画
        this.feedbackPanel.getComponent(Animation).play();
    }
    start() {

    }

    update(deltaTime: number) {
        
    }

    closeFeedback() {
        this.node.active = false;
    }

    async sendFeedback() {
        const feedbackContent = this.FeedbackBox.getComponent(EditBox).string;
        try {
            const response = await GLOBALUtil.sendFeedback(feedbackContent);
            GLOBALUtil.LoadMessage(true, response.msg, this.node, new Vec3(50, 950, 0), true, 1);
        } catch (error) {
            GLOBALUtil.LoadMessage(true, '反馈失败！', this.node, new Vec3(50, 950, 0), true, 2);
            console.error(error);
        }
    }
}


